package org.apache.lenya.modules.xmldiff.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;

public class ArrayUtil {

	public static int[] unique(int[] source) {
		Collection temp = new ArrayList();
		for (int i = 0; i < source.length; i++) {
			temp.add(Integer.valueOf(source[i]));
		}
		HashSet set = new HashSet(temp);
		int[] result = new int[set.size()];
		int j = set.size() - 1;
		for (Iterator iterator = set.iterator(); iterator.hasNext();) {
			Integer rn = (Integer) iterator.next();
			result[j--] = rn.intValue();
		}
		return result;
	}
	
	public static int findInUnsorted(int[] array, int value) {
		int j = -1;
		int revIdx = -1;
		while (++j < array.length) {
			if (array[j] == value) {
				revIdx = j;
			}
		}
		return revIdx;
	}
	
}
